// utils/env.js
export function getEnv() {
  let platform = ''
  let os = ''

  // 1. 小程序平台判断
  // #ifdef MP-WEIXIN
  platform = 'weixin'
  // #endif

  // #ifdef MP-ALIPAY
  platform = 'alipay'
  // #endif

  // 2. APP 平台判断
  // #ifdef APP-PLUS
  const systemInfo = uni.getSystemInfoSync()
  if (systemInfo.platform === 'android') {
    platform = 'app'
    os = 'android'
  } else if (systemInfo.platform === 'ios') {
    platform = 'app'
    os = 'ios'
  }
  // #endif

  // 3. H5 平台判断
  // #ifdef H5
  platform = 'h5'
  const ua = navigator.userAgent.toLowerCase()
  if (/micromessenger/.test(ua)) {
    os = 'weixin-h5'
  } else if (/alipayclient/.test(ua)) {
    os = 'alipay-h5'
  } else if (/android/.test(ua)) {
    os = 'android'
  } else if (/iphone|ipad|ipod/.test(ua)) {
    os = 'ios'
  }
  // #endif

  return { platform, os }
}


export const provider = {
  weixin: 1,
  alipay: 2,
  android: 3,
  ios: 4,
}